pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let mut num_iter = num_str.trim_end_matches(")").split('(');
    let num = num_iter.next().unwrap();
    let base = num_iter.next().unwrap();

    let base = u32::from_str_radix(base, 10).unwrap();
    assert!(2 <= base && base <= 16);
    let mut num = u32::from_str_radix(num, base).unwrap();
    if num == 0 {
        return "0".into();
    }
    let mut res = String::new();
    while num != 0 {
        let dig = num % to_base; 
        num /= to_base;
        // We can assume that the conversion is valid.
        if dig < 10 {
            res.push((dig + ('0' as u32)) as u8 as char);
        } else {
            res.push((dig - 10 + ('a' as u32)) as u8 as char);
        }
    }

    res.chars().rev().collect()
}
